package com.ruoyi.web.admin.data;

import com.ruoyi.web.admin.data.utils.CommonUtils;

/**
 * @author 10100
 * @license (C) Copyright 2020-2050,  Corporation Limited.
 * @contact wang.he@cpe-smartcity.com
 * @date 2025-06-10 17:31
 * @description 平台下发指令构建
 */
public class CommandMessageBuilder {

    public static String buildSetServerMessage(String deviceId, String iccid, String responseBody) {
        String command = "SET_SERVER_INFO";
        return buildCommandMessage(deviceId, iccid, command, responseBody);
    }

    public static String buildGetLocationMessage(String deviceId, String iccid) {
        String command = "LOCATION_INFO_GET";
        return buildCommandMessage(deviceId, iccid, command, "");
    }

    public static String buildLocationSeqSetMessage(String deviceId, String iccid, String seq) {
        /*上报频率(单位分钟)最小值 5 分*/
        String command = "FREQUENCY_LOCATION_SET";
        return buildCommandMessage(deviceId, iccid, command, seq);
    }

    public static String buildLocationSeq2SetMessage(String deviceId, String iccid, String seq) {
        /*ZF1036 上报频率(单位秒)最小值 10 秒，最大值 999 秒*/
        String command = "FREQUENCY_LOCATION_SET2";
        return buildCommandMessage(deviceId, iccid, command, seq);
    }

    public static String buildLocationModeSetMessage(String deviceId, String iccid, String model) {
        /* 1 省电模式省电模式下设备可主动定位，保持正常心跳。 设备不主动上报位置。原有课堂模式，情景模式，白名单均正常生效。
         * 2 平衡模式平衡模式下设备可主动定位，保持正常心跳。 设备每 20分钟为基准，上报一次当前位置。 原有课堂模式，情景模式，白名单均正常生效。
         * 3 实时模式设备与平台保持正常心跳，每 3 分钟上报一次 位置信息。每次切换模式后立即上报一次当前位置。
         */
        String command = "SET_LOCATION_MODE";
        return buildCommandMessage(deviceId, iccid, command, model);
    }

    public static String buildHealthIntervalMessage(String deviceId, String iccid, String interval) {
        /* 设置健康数据上报频率*/
        String command = "SET_HEALTH_INTERVAL";
        return buildCommandMessage(deviceId, iccid, command, interval);
    }


    public static String buildCommandMessage(String deviceId, String iccid, String command, String responseBody) {
        /*请求示例 [782878287828782,89860802012080190008,202110181530560049,SET_SERVER_INFO,1,20211018153056,17,1.14.179.202@7999]*/
        /*[deviceId,iccid,流水号,指令,报文类型,时间戳,报文长度,报文]*/
        // 构建响应格式
        return "[" + deviceId + "," +
                iccid + "," +
                CommonUtils.generateSerialNumber() + "," +
                command + "," +
                Constants.DISTRIBUTE_REQUEST + "," +
                CommonUtils.getCurrentTimestamp() + "," +
                responseBody.length() + "," +
                responseBody + "]";
    }
}